<template>
    <modal
        v-bind="modalProps"
        @confirm="confirm"
        @cancel="cancel"
        @done="$emit('done', lastRes)"
    >
        <input type="text" class="form-control mx-auto my-2" v-model="name"/>
    </modal>
    <!-- <div class="modal fade" tabindex="-1" role="dialog">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title">{{title}}</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"  @click="cancel">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            
            
          </div>
          <div class="modal-footer d-flex align-items-center py-2">
            <Footer
                :
            />
            <div class="alert alert-danger fade ml-1 mr-auto my-0 py-2" role="alert" :class="{show: isFailed}">
              {{lastRes && lastRes.msg}}
            </div>
            <button type="button" class="btn btn-sm btn-primary m-1"  @click="confirm" :disabled="!isSendValid" v-if="!isFailed">确定</button>
            <button type="button" class="btn btn-sm btn-danger m-1"  @click="confirm" :disabled="!isSendValid" v-else>重试</button>
            <button type="button" class="btn btn-sm btn-success m-1"  @click="$emit('done', lastRes)" v-if="isSucceed">完成</button>
            <button type="button" class="btn btn-sm btn-secondary m-1" data-dismiss="modal" @click="cancel" :disabled="isLoading" v-else>取消</button>
          </div>
        </div>
      </div>
    </div> -->
</template>
<script type="text/javascript">
import ajaxModal from '../plugin/ajaxModal'
import {defaultModal as modal} from '../plugin/ajaxModal'
import $ from 'jquery'

export default {
    name: 'name-modal',
    props: ['doc', 'args'],
    mixins: [ajaxModal],
    components: {modal},
    data() {
        return {
            name: this.doc.name,
            doc_id: this.doc._id
        }
    },
    computed: {
        isSendValid() {
            return !this.isLoading && this.name != this.doc.name && this.name.length;
        }
    },
    methods: {
        getParams() {
            var vm = this, args = $.isFunction(vm.args) ? vm.args() : vm.args || {};
            return {
                _id: vm.doc_id,
                args: Object.assign({
                    name: vm.name
                }, args)
            }
        }
    }
}
</script>